<?php namespace Home\Controller;
use Hdphp\Controller\Controller;
use \Common\Model\TypeAttr;
use \Common\Model\GoodsAttr;
class CartController extends Controller{
	public function index(){
		if(isset($_GET['d']))
    		Cart::del($_GET['d']);
		$data=$_SESSION;
		// p($data);
		View::with('data',$data);
		
		View::make();

	}
	public function getCart(){
        $typeAttrModel=new TypeAttr();
		$GoodsAttrModel=new GoodsAttr();
		// p(Q('post.'));
		$cartcombo=rtrim(Q('post.str'),',');
		$cartprice=ltrim(Q('post.cartprice'),'￥');
		$cartnum=Q('post.cartnum');
		$cartname=Q('post.cartname');
		$gid=Q('post.gid');
		// p($gid);
		//找出货品对应的分类属性
		$temp=$GoodsAttrModel
		     ->join('goods_list','goods_attr.goods_gid','=','goods_list.goods_gid')
			 ->join('type_attr','type_attr_taid','=','taid')
			 ->join('goods',"goods_attr.goods_gid",'=',"gid")
			 ->where("combo='{$cartcombo}' AND goods_attr.goods_gid={$gid}")->find();
		$combo=explode(',',$temp['combo']);
		$name=[];
		//找出分类属性对应的类型属性
		foreach ($combo as $k => $v) {
			$cType=$typeAttrModel->join('goods_attr','taid','=','type_attr_taid') ->where("gtid=$v")->find();
			// p($cType);
			$name[]=[
				'name'=>$cType['taname'],
				'value'=>$cType['gtvalue']
			];
		 }
		$temp['name']=$name;
		$data = [
            'id'        =>$gid, // 商品 ID
            'name'      =>$cartname,// 商品名称
            'num'       =>$cartnum, // 商品数量
            'price'     =>$cartprice, // 商品价格
            'options' => $temp
            ];
        Cart::add($data);
        p($_SESSION);
    }
    
	
}